/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * SearchOrder.java
 *
 * Created on 21-08-2011, 12:18:56
 */
package tuitionmanagement.gui;

import Business.OrderBuss;
import java.util.ArrayList;
import java.util.Date;
import java.util.Vector;
import javax.swing.table.DefaultTableModel;
import tuitionmanagement.entity.OrderEntity;

/**
 *
 * @author XUAN
 */
public class SearchOrder extends javax.swing.JPanel {

    Vector vcr = new Vector();
    Vector vRow = new Vector();
    ArrayList<OrderEntity> listor;
    OrderBuss orbuss = new OrderBuss();
    OrderEntity ord = new OrderEntity();

    /** Creates new form SearchOrder */
    public SearchOrder() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        btnSearchOrder = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        dcFrom = new com.toedter.calendar.JDateChooser();
        dcTo = new com.toedter.calendar.JDateChooser();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tbSearchOrder = new javax.swing.JTable();
        jPanel4 = new javax.swing.JPanel();
        btnReport = new javax.swing.JButton();
        jPanel5 = new javax.swing.JPanel();
        txtlablemeassage = new javax.swing.JLabel();

        setLayout(new java.awt.GridBagLayout());

        jPanel1.setLayout(new java.awt.GridBagLayout());

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 18));
        jLabel1.setForeground(new java.awt.Color(0, 0, 255));
        jLabel1.setText("Search Order");
        jPanel1.add(jLabel1, new java.awt.GridBagConstraints());

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.insets = new java.awt.Insets(10, 0, 10, 0);
        add(jPanel1, gridBagConstraints);

        jPanel2.setLayout(new java.awt.GridBagLayout());

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel2.setText("To");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.insets = new java.awt.Insets(0, 15, 0, 6);
        jPanel2.add(jLabel2, gridBagConstraints);

        btnSearchOrder.setFont(new java.awt.Font("Tahoma", 0, 12));
        btnSearchOrder.setIcon(new javax.swing.ImageIcon(getClass().getResource("/tuitionmanagement/icon/view.png"))); // NOI18N
        btnSearchOrder.setText("Search");
        btnSearchOrder.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSearchOrderActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 5;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.insets = new java.awt.Insets(5, 10, 5, 10);
        jPanel2.add(btnSearchOrder, gridBagConstraints);

        jLabel3.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel3.setText("Date:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.insets = new java.awt.Insets(0, 7, 0, 6);
        jPanel2.add(jLabel3, gridBagConstraints);

        jLabel4.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel4.setText("From");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.insets = new java.awt.Insets(0, 7, 0, 6);
        jPanel2.add(jLabel4, gridBagConstraints);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.ipadx = 110;
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 6);
        jPanel2.add(dcFrom, gridBagConstraints);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 4;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.ipadx = 110;
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 6);
        jPanel2.add(dcTo, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.insets = new java.awt.Insets(10, 0, 10, 0);
        add(jPanel2, gridBagConstraints);

        jPanel3.setLayout(new java.awt.GridBagLayout());

        tbSearchOrder.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null}
            },
            new String [] {
                "OrderId", "InvoiceId", "Money", "FeeDate", "RateId"
            }
        ));
        jScrollPane1.setViewportView(tbSearchOrder);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.ipadx = 600;
        gridBagConstraints.ipady = 200;
        jPanel3.add(jScrollPane1, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.insets = new java.awt.Insets(10, 0, 10, 0);
        add(jPanel3, gridBagConstraints);

        jPanel4.setLayout(new java.awt.GridBagLayout());

        btnReport.setFont(new java.awt.Font("Tahoma", 0, 12));
        btnReport.setIcon(new javax.swing.ImageIcon(getClass().getResource("/tuitionmanagement/icon/export1.png"))); // NOI18N
        btnReport.setText("Report");
        jPanel4.add(btnReport, new java.awt.GridBagConstraints());

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.insets = new java.awt.Insets(10, 0, 10, 21);
        add(jPanel4, gridBagConstraints);

        jPanel5.setLayout(new java.awt.GridBagLayout());
        jPanel5.add(txtlablemeassage, new java.awt.GridBagConstraints());

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.insets = new java.awt.Insets(10, 0, 10, 0);
        add(jPanel5, gridBagConstraints);
    }// </editor-fold>//GEN-END:initComponents

    private void loadTableOrderSearch() {
        vRow.clear();
        Date searchFrom = dcFrom.getDate();
        Date searchTo = dcTo.getDate();
        listor = orbuss.getOrderByDate(searchFrom, searchTo);

//        ArrayList<OrderEntity> lstOrder = new ArrayList<OrderEntity>();
//        lstOrder = listor;

        for (int i = 0; i < listor.size(); i++) {
            Vector v = new Vector();

            ord = listor.get(i);
            v.addElement(ord.getOrderId());
            v.addElement(ord.getInvoiceId());
            v.addElement(ord.getMoney());
            v.addElement(ord.getFeeDate());            
            v.addElement(ord.getRateId());

            vRow.addElement(v);
        }

        Vector vCol = new Vector();
        vCol.addElement("OrderId");
        vCol.addElement("InvoiceId");
        vCol.addElement("Money");
        vCol.addElement("FeeDate");
        vCol.addElement("RateId");

        DefaultTableModel tblModel = new DefaultTableModel(vRow, vCol);
        tbSearchOrder.setModel(tblModel);
    }

    private void btnSearchOrderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSearchOrderActionPerformed
        // TODO add your handling code here:
        loadTableOrderSearch();
        int result = tbSearchOrder.getRowCount();
        if (result == 0) {
            txtlablemeassage.setText("No results match.");
        } else {
            txtlablemeassage.setText(result + " results match.");
        }

//        vcr.clear();
//        this.tbSearchOrder.updateUI();

    }//GEN-LAST:event_btnSearchOrderActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnReport;
    private javax.swing.JButton btnSearchOrder;
    private com.toedter.calendar.JDateChooser dcFrom;
    private com.toedter.calendar.JDateChooser dcTo;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable tbSearchOrder;
    private javax.swing.JLabel txtlablemeassage;
    // End of variables declaration//GEN-END:variables
}
